package com.tc.nio;

import com.tc.util.ByteBufferUtil;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

/**
 * @Auther: tianchao
 * @Date: 2022/2/7 16:47
 * @Description:
 */
public class TestByteBufferClearAndCompact {
    public static void main(String[] args) {
        // 读模式
        ByteBuffer byteBuffer = Charset.defaultCharset().encode("123456789");
        ByteBufferUtil.debugAll(byteBuffer);
        byteBuffer.get();
        byteBuffer.flip();
        ByteBufferUtil.debugAll(byteBuffer);
        System.out.println("==================================clear=======================");
        byteBuffer.compact();
        ByteBufferUtil.debugAll(byteBuffer);
        final byte b = byteBuffer.get();
        System.out.println((char) b);
        ByteBufferUtil.debugAll(byteBuffer);
        byteBuffer.put((byte) 40);
        ByteBufferUtil.debugAll(byteBuffer);
    }
}
